package com.tsing.cloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author TheTsing
 * @version 1.0
 * @date 2021/11/8 15:02
 */
@Service
public class PaymentService {

    /**
     * 设置自身调用超时时间的峰值，峰值内可以正常运行，超过了需要有兜底方法处理，作服务降级fallback
     */
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000")})
    public String paymentInfo_TimeOut() {
        try {
            TimeUnit.MILLISECONDS.sleep(2500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "8002成功";
    }

    public String paymentInfo_TimeOutHandler() {
        return "8002系统繁忙";
    }

}
